package com.yanqu.road.logic.activity;

import com.yanqu.road.entity.activity.yearMaster.YearMasterBossStateConfig;
import com.yanqu.road.entity.activity.yearMaster.YearMasterConfig;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

public class YearMasterLogic {
    public static Map<Integer, Long> pareStateHpMap(Map<Integer, YearMasterConfig> yearMasterBossConfig, Map<Integer, YearMasterBossStateConfig> yearMasterStateMap) {
        //状态对应血量
        Map<Integer, Long> stateHpMap = new HashMap<>();

        //计算每个状态需要的血量
        for (int i = 1; i <= yearMasterBossConfig.size(); i++) {
            YearMasterConfig currentYearMasterConfig = yearMasterBossConfig.get(i);
            YearMasterConfig lastYearMasterConfig = yearMasterBossConfig.get(i - 1);

            long currentHp = currentYearMasterConfig.getHp();
            if (lastYearMasterConfig != null) {
                currentHp = currentHp - lastYearMasterConfig.getHp();
            }

            for (int j = 0; j < yearMasterStateMap.size(); j++) {
                YearMasterBossStateConfig currentState = yearMasterStateMap.get(j);
                int bloodPercent = currentState.getBloodPercent();
                long result = new BigDecimal(bloodPercent).divide(BigDecimal.valueOf(1000))
                        .multiply(new BigDecimal(currentHp))
                        .setScale(0, BigDecimal.ROUND_UP).toBigInteger().longValue();


                int state = (currentYearMasterConfig.getLevel() - 1) * yearMasterStateMap.size() + currentState.getState() + 1;

                //之前等级血量+ 当前等级阶段的血量
                if (lastYearMasterConfig != null) {
                    result += lastYearMasterConfig.getHp();
                }

                stateHpMap.put(state, result);
            }
        }
        return  stateHpMap;
    }
}
